<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="物料编码" prop="fnumber">
          <el-input v-model="query.fnumber" name="fnumber" clearable />
        </el-form-item>
        <el-form-item label="物料名称" prop="fname">
          <el-input v-model="query.fname" name="fname" clearable />
        </el-form-item>
        <el-form-item label="分类编码" prop="fbaseproperty_number" v-if="!prop.isVue">
          <el-input v-model="query.fbaseproperty_number" name="fbaseproperty_number" clearable />
        </el-form-item>
      </template>
    </Search>
    <div class="table-default" ref="tableDefault">
      <!--<Operate :show="open" />-->
      <el-table :data="tableData" class="el-table" v-loading="loading" border v-if="tableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" v-if="prop.isVue" />
        <el-table-column prop="fnumber" label="物料编码" width="120" />
        <el-table-column prop="fname" label="物料名称" width="500" v-if="prop.isVue" />
        <el-table-column prop="fname" label="物料名称" width="300" v-if="!prop.isVue" />
        <el-table-column prop="fspecification" label="物料规格" width="200" v-if="!prop.isVue" />
        <el-table-column prop="funit_number" label="单位编码" v-if="!prop.isVue" />
        <el-table-column prop="funit_name" label="单位名称" v-if="!prop.isVue" />
        <el-table-column prop="fuseorgid_name" label="组织名称" v-if="!prop.isVue" />
        <el-table-column prop="fbaseproperty_number" label="分类编码" v-if="!prop.isVue" />
        <el-table-column prop="fbaseproperty_name" label="分类名称" width="100" v-if="!prop.isVue" />
        <el-table-column prop="fdocumentstatus" label="数据状态" v-if="!prop.isVue">
          <template #default="scope">
            <el-tag v-if="scope.row.fdocumentstatus == 0" class="ml-2" type="danger">未审核</el-tag>
            <el-tag v-if="scope.row.fdocumentstatus == 1" class="ml-2">已审核</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="fforbidstatus" label="禁用状态" v-if="!prop.isVue">
          <template #default="scope">
            <el-tag v-if="scope.row.fforbidstatus == 0" class="ml-2" type="danger">禁用</el-tag>
            <el-tag v-if="scope.row.fforbidstatus == 1" class="ml-2">启用</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="fcasecode" label="启用箱号" v-if="!prop.isVue">
          <template #default="scope">
            <el-tag v-if="scope.row.fcasecode == 0" class="ml-2" type="danger">否</el-tag>
            <el-tag v-if="scope.row.fcasecode == 1" class="ml-2">是</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="添加时间" width="150" v-if="!prop.isVue" />
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, ref, provide } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import { setTableHeight } from '/admin/utils/setHeight.js'

const api = 'base/material'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

let prop = defineProps({
  isVue: {
    type: Boolean,
    default: false,
  },
})

let multipleSelection = ref([])

let emit = defineEmits(['send-materail'])

const handleSelectionChange = val => {
  console.log('选中的物料', val)
  multipleSelection.value = val
  emit('send-materail',val)
}



onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')
})
</script>

<style lang="css">
.el-table {
  height: 87%;
}
</style>
